package rickyGame.game.action
{
	import flash.utils.getQualifiedClassName;
	
	import ricky.events.AnimEvent;
	import ricky.game.Actor;
	import ricky.game.action.Act2D;
	import ricky.game.graphic.Graphic;
	
	/**
	 * 角色动画播放行动
	 * 主动行动 
	 * 注意对玩家自己的行动需要调用此类
	 * 对其他角色的行动影响请用TargetAct
	 */
	public class AnimaAct extends Act2D
	{
		public function AnimaAct(actor:Actor=null, animPro:String=null)
		{
			super(actor);
			this._animProperty=animPro;
			_type="AnimaAct";
		}
		
		override public function begin():void
		{
			super.begin();

			var g:Graphic=actor.graphic as Graphic;
			g.clothes.addEventListener(AnimEvent.Anim_Effect,animEffctFun);
			g.clothes.addEventListener(AnimEvent.Anim_End,animEndFun);
		}
		
		private function animEffctFun(e:*):void
		{
			if(	_state<3)
			{
				Graphic(actor.graphic).clothes.removeEventListener(AnimEvent.Anim_Effect,animEffctFun);
				if(this._effectNext)
					ActionHelper.inst.addAct(_effectNext);
			}
			
		}
		
		private function animEndFun(e:*):void
		{
			if(_state<3)
			{
				Graphic(actor.graphic).clothes.removeEventListener(AnimEvent.Anim_End,animEndFun);
				this.complete();
			}
		}
		
		override public function end():void
		{
//			JDebug.trace(actor+"animaAct行动结束");
//			this.actor.graphic.clothes.removeEventListener(AnimEvent.Anim_Effect,animEffctFun);
//			this.actor.graphic.clothes.removeEventListener(AnimEvent.Anim_End,animEndFun);
			super.end();
		}
		
		override public function dispose():void
		{
//			JDebug.trace(this+"animaAct销毁行动 "+animProperty);

			super.dispose();
		}
	
	}
}